package com.jungle.client.vo;


import com.jungle.bfi.domain.vo.Option;
import javafx.beans.property.SimpleBooleanProperty;
import lombok.Getter;
import lombok.Setter;

import java.util.StringJoiner;

@Setter
@Getter
public class DataDefinitionVo {
    private String id;
    /**
     * 接口标识
     */
    private String apiId;
    /**
     * 接口请求路径
     */
    private String apiPath;

    /**
     * 数据标题
     */
    private String title;
    /**
     * 数据显示名称
     */
    private String name;
    private String namePath;
    /**
     * 数据值
     */
    private String code;
    private String codePath;
    /**
     * 业务场景标识因子数据
     */
    private final SimpleBooleanProperty scenarioFlag = new SimpleBooleanProperty(this, "scenarioFlag", false);

    public Boolean isScenarioFlag() {
        return scenarioFlag.get();
    }

    public SimpleBooleanProperty scenarioFlagProperty() {
        return scenarioFlag;
    }

    public void setScenarioFlag(boolean scenarioFlag) {
        this.scenarioFlag.set(scenarioFlag);
    }
    /**
     * 是否必填项
     */
    private Boolean required;

    /**
     * 业务数据类别-编码
     */
    private String categoryValue;
    /**
     * 业务数据类别-名称
     */
    private String categoryName;
    /**
     * 数据源类型：api-接口返回数据，enum-枚举数据
     */
    private String dataSourceType;
    /**
     * 数据集标识
     */
    private String datasetId;
    /**
     * 数据集名称
     */
    private String datasetName;

    public void setCategory(Option category) {
        if (category != null) {
            this.categoryName = category.getName();
            this.categoryValue = category.getValue();
        }
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", DataDefinitionVo.class.getSimpleName() + "[", "]")
                .add("id='" + id + "'")
                .add("apiId='" + apiId + "'")
                .add("apiPath='" + apiPath + "'")
                .add("title='" + title + "'")
                .add("name='" + name + "'")
                .add("namePath='" + namePath + "'")
                .add("code='" + code + "'")
                .add("codePath='" + codePath + "'")
                .add("scenarioFlag=" + scenarioFlag.get())
                .add("categoryValue='" + categoryValue + "'")
                .add("categoryName='" + categoryName + "'")
                .add("dataSourceType='" + dataSourceType + "'")
                .add("datasetId='" + datasetId + "'")
                .add("datasetName='" + datasetName + "'")
                .toString();
    }

    public static com.jungle.bfi.domain.vo.DataDefinitionVo copy(DataDefinitionVo vo) {
        com.jungle.bfi.domain.vo.DataDefinitionVo vo1 = new com.jungle.bfi.domain.vo.DataDefinitionVo();
        vo1.setId(vo.getId());
        vo1.setApiId(vo.getApiId());
        vo1.setApiPath(vo.getApiPath());
        vo1.setTitle(vo.getTitle());
        vo1.setName(vo.getName());
        vo1.setCode(vo.getCode());
        vo1.setCategoryValue(vo.getCategoryValue());
        vo1.setCategoryName(vo.getCategoryName());
        vo1.setDataSourceType(vo.getDataSourceType());
        vo1.setDatasetId(vo.getDatasetId());
        vo1.setDatasetName(vo.getDatasetName());
        vo1.setNamePath(vo.getNamePath());
        vo1.setCodePath(vo.getCodePath());
        vo1.setRequired(vo.getRequired());

        vo1.setScenarioFlag(vo.isScenarioFlag());
        return vo1;
    }

    public static DataDefinitionVo from(com.jungle.bfi.domain.vo.DataDefinitionVo vo) {
        DataDefinitionVo vo1 = new DataDefinitionVo();
        vo1.setId(vo.getId());
        vo1.setApiId(vo.getApiId());
        vo1.setApiPath(vo.getApiPath());
        vo1.setTitle(vo.getTitle());
        vo1.setName(vo.getName());
        vo1.setCode(vo.getCode());
        vo1.setCategoryValue(vo.getCategoryValue());
        vo1.setCategoryName(vo.getCategoryName());
        vo1.setDataSourceType(vo.getDataSourceType());
        vo1.setDatasetId(vo.getDatasetId());
        vo1.setDatasetName(vo.getDatasetName());
        vo1.setNamePath(vo.getNamePath());
        vo1.setCodePath(vo.getCodePath());
        vo1.setRequired(vo.getRequired());

        vo1.setScenarioFlag(vo.getScenarioFlag() != null && vo.getScenarioFlag());
        return vo1;
    }

}
